home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
src.arc
/
TCPCMD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-19
|
7KB
|
290 lines
#include <stdio.h>
#include "global.h"
#include "timer.h"
#include "mbuf.h"
#include "netuser.h"
#include "internet.h"
#include "tcp.h"
#include "cmdparse.h"
#include "commands.h"
extern char Notval[];
static int doirtt __ARGS((int argc,char *argv[],void *p));
static int domss __ARGS((int argc,char *argv[],void *p));
static int dortt __ARGS((int argc,char *argv[],void *p));
static int dotcpkick __ARGS((int argc,char *argv[],void *p));
static int dotcpreset __ARGS((int argc,char *argv[],void *p));
static int dotcpstat __ARGS((int argc,char *argv[],void *p));
static int dotcptr __ARGS((int argc,char *argv[],void *p));
static int dowindow __ARGS((int argc,char *argv[],void *p));
static int tstat __ARGS((void));
/* TCP subcommand table */
static struct cmds Tcpcmds[] = {
"irtt", doirtt, 0, 0, NULLCHAR,
"kick", dotcpkick, 0, 2, "tcp kick <tcb>",
"mss", domss, 0, 0, NULLCHAR,
"reset", dotcpreset, 0, 2, "tcp reset <tcb>",
"rtt", dortt, 0, 3, "tcp rtt <tcb> <val>",
"status", dotcpstat, 0, 0, NULLCHAR,
"trace", dotcptr, 0, 0, NULLCHAR,
"window", dowindow, 0, 0, NULLCHAR,
NULLCHAR,
};
int
dotcp(argc,argv,p)
int argc;
char *argv[];
void *p;
{
return subcmd(Tcpcmds,argc,argv,p);
}
static int
dotcptr(argc,argv,p)
int argc;
char *argv[];
void *p;
{
return setbool(&Tcp_trace,"TCP state tracing",argc,argv);
}
/* Eliminate a TCP connection */
static int
dotcpreset(argc,argv,p)
int argc;
char *argv[];
void *p;
{
register struct tcb *tcb;
tcb = (struct tcb *)ltop(htol(argv[1]));
if(!tcpval(tcb)){
printf(Notval);
return 1;
}
close_self(tcb,RESET);
return 0;
}
/* Set initial round trip time for new connections */
static int
doirtt(argc,argv,p)
int argc;
char *argv[];
void *p;
{
struct tcp_rtt *tp;
setlong(&Tcp_irtt,"TCP default irtt",argc,argv);
if(argc < 2){
for(tp = &Tcp_rtt[0];tp < &Tcp_rtt[RTTCACHE];tp++){
if(tp->addr != 0){
printf("%s: srtt %lu mdev %lu\n",
inet_ntoa(tp->addr),
tp->srtt,tp->mdev);
}
}
}
return 0;
}
/* Set smoothed round trip time for specified TCB */
static int
dortt(argc,argv,p)
int argc;
char *argv[];
void *p;
{
register struct tcb *tcb;
tcb = (struct tcb *)ltop(htol(argv[1]));
if(!tcpval(tcb)){
printf(Notval);
return 1;
}
tcb->srtt = atol(argv[2]);
return 0;
}
/* Force a retransmission */
static int
dotcpkick(argc,argv,p)
int argc;
char *argv[];
void *p;
{
register struct tcb *tcb;
tcb = (struct tcb *)ltop(htol(argv[1]));
if(kick_tcp(tcb) == -1){
printf(Notval);
return 1;
}
return 0;
}
/* Set default maximum segment size */
static int
domss(argc,argv,p)
int argc;
char *argv[];
void *p;
{
return setshort(&Tcp_mss,"TCP MSS",argc,argv);
}
/* Set default window size */
static int
dowindow(argc,argv,p)
int argc;
char *argv[];
void *p;
{
return setshort(&Tcp_window,"TCP window",argc,argv);
}
/* Display status of TCBs */
static int
dotcpstat(argc,argv,p)
int argc;
char *argv[];
void *p;
{
register struct tcb *tcb;
if(argc < 2){
tstat();
} else {
tcb = (struct tcb *)ltop(htol(argv[1]));
if(tcpval(tcb))
st_tcp(tcb);
else
printf(Notval);
}
return 0;
}
/* Dump TCP stats and summary of all TCBs
/* &TCB Rcv-Q Snd-Q Local socket Remote socket State
* 1234 0 0 xxx.xxx.xxx.xxx:xxxxx xxx.xxx.xxx.xxx:xxxxx Established
*/
static int
tstat()
{
register int i;
register struct tcb *tcb;
printf("conout %u conin %u reset out %u runt %u chksum err %u bdcsts %u\n",
Tcp_stat.conout,Tcp_stat.conin,Tcp_stat.resets,Tcp_stat.runt,
Tcp_stat.checksum,Tcp_stat.bdcsts);
printf(" &TCB Rcv-Q Snd-Q Local socket Remote socket State\n");
for(i=0;i<NTCB;i++){
for(tcb=Tcbs[i];tcb != NULLTCB;tcb = tcb->next){
printf("%8lx%6u%6u ",ptol(tcb),tcb->rcvcnt,tcb->sndcnt);
printf("%-23s",pinet(&tcb->conn.local));
printf("%-23s",pinet(&tcb->conn.remote));
printf("%-s",Tcpstates[tcb->state]);
if(tcb->state == LISTEN && tcb->flags.clone)
printf(" (S)");
printf("\n");
}
}
return 0;
}
/* Dump a TCP control block in detail */
void
st_tcp(tcb)
struct tcb *tcb;
{
int32 sent,recvd;
if(tcb == NULLTCB)
return;
/* Compute total data sent and received; take out SYN and FIN */
sent = tcb->snd.una - tcb->iss; /* Acknowledged data only */
recvd = tcb->rcv.nxt - tcb->irs;
switch(tcb->state){
case LISTEN:
case SYN_SENT: /* Nothing received or acked yet */
sent = recvd = 0;
break;
case SYN_RECEIVED:
recvd--; /* Got SYN, no data acked yet */
sent = 0;
break;
case ESTABLISHED: /* Got and sent SYN */
case FINWAIT1: /* FIN not acked yet */
sent--;
recvd--;
break;
case FINWAIT2: /* Our SYN and FIN both acked */
sent -= 2;
recvd--;
break;
case CLOSE_WAIT: /* Got SYN and FIN, our FIN not yet acked */
case CLOSING:
case LAST_ACK:
sent--;
recvd -= 2;
break;
case TIME_WAIT: /* Sent and received SYN/FIN, all acked */
sent -= 2;
recvd -= 2;
break;
}
printf("Local: %s",pinet(&tcb->conn.local));
printf(" Remote: %s",pinet(&tcb->conn.remote));
printf(" State: %s\n",Tcpstates[tcb->state]);
printf(" Init seq Unack Next Resent CWind Thrsh Wind MSS Queue Total\n");
printf("Send:");
printf("%9lx",tcb->iss);
printf("%9lx",tcb->snd.una);
printf("%9lx",tcb->snd.nxt);
printf("%7lu",tcb->resent);
printf("%6u",tcb->cwind);
printf("%6u",tcb->ssthresh);
printf("%6u",tcb->snd.wnd);
printf("%5u",tcb->mss);
printf("%6u",tcb->sndcnt);
printf("%11lu\n",sent);
printf("Recv:");
printf("%9lx",tcb->irs);
printf(" ");
printf("%9lx",tcb->rcv.nxt);
printf("%7lu",tcb->rerecv);
printf(" ");
printf(" ");
printf("%6u",tcb->rcv.wnd);
printf(" ");
printf("%6u",tcb->rcvcnt);
printf("%11lu\n",recvd);
if(tcb->reseq != (struct reseq *)NULL){
register struct reseq *rp;
printf("Reassembly queue:\n");
for(rp = tcb->reseq;rp != (struct reseq *)NULL; rp = rp->next){
printf(" seq x%lx %u bytes\n",rp->seg.seq,rp->length);
}
}
if(tcb->backoff > 0)
printf("Backoff %u ",tcb->backoff);
if(tcb->flags.retran)
printf("Retrying ");
switch(tcb->timer.state){
case TIMER_STOP:
printf("Timer stopped ");
break;
case TIMER_RUN:
printf("Timer running (%ld/%ld ms) ",
(long)MSPTICK * read_timer(&tcb->timer),
(long)MSPTICK * dur_timer(&tcb->timer));
break;
case TIMER_EXPIRE:
printf("Timer expired ");
}
printf("SRTT %ld ms Mean dev %ld ms\n",tcb->srtt,tcb->mdev);
}